Skip to content

asahi/compiler: skip non-register PHI sources before class assert in agx_validate_ra - #1321

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
satya/fix-validate-ra-spilled-phi
Nov 29, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
satya/fix-validate-ra-spilled-phi

Conversation

@satchlj

@satchlj satchlj commented Nov 29, 2026

Copy link
Copy Markdown
Member

What

In validate_block() (src/asahi/compiler/agx_validate_ra.c), non-loop-header PHI validation asserted ra_class_for_index(src) == cls before checking if (!src.has_reg). When a spilled PHI destination (RA_MEM) has an immediate or other non-register source (memory == 0, has_reg == false), ra_class_for_index(src) returns RA_GPR and trips the assertion on assertion-enabled (-Db_ndebug=false) builds (reproduced on spilling compute shaders in llama.cpp Vulkan pp512).

Move the if (!src.has_reg) continue; guard before the ra_class_for_index(src) == cls assertion, and add a unit test in src/asahi/compiler/test/test-native-form-regressions.cpp covering a spilled non-loop-header PHI with an immediate source.

Tested

  • Exact head: 3d89c681dd67 on Apple M5 Max (J775c, G17C B1), -Dbuildtype=release -Db_ndebug=false.
  • MALLOC_PERTURB_=42 meson test -C build --suite asahi: 348/348 PASS (0 fail, including new NativeFormRegressions.ValidateRASpilledPhiImmediateSource).
  • Live Borealis Vulkan llama-bench (Llama-2-7B Q4_0, spilling path without drirc override, MESA_SHADER_CACHE_DISABLE=true, -Db_ndebug=false): previously aborted in validate_block(), now compiles and runs cleanly to completion with 0 GPU faults.

Risk

Minimal: only reorders an existing !src.has_reg early-continue before a debug-only assertion in agx_validate_ra.c.

…agx_validate_ra

In validate_block(), non-loop-header PHI validation asserted
ra_class_for_index(src) == cls before checking if (!src.has_reg). When a
spilled PHI destination (RA_MEM) has an immediate or other non-register
source (memory == 0, has_reg == false), ra_class_for_index(src) returned
RA_GPR and tripped the assertion on debug/assertion-enabled builds (e.g.,
spilling compute shaders in llama.cpp Vulkan pp512).

Check !src.has_reg before asserting the register class, and add a unit test
covering a spilled non-loop-header PHI with an immediate source.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners November 29, 2026 00:37

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 3d89c681.

Blockers: none.

Checked: Full 2-file diff (src/asahi/compiler/agx_validate_ra.c, src/asahi/compiler/test/test-native-form-regressions.cpp), validate_block() PHI source loop invariants, unit test coverage, and exact-head J775c (G17C B1, -Db_ndebug=false) verification.

Evidence
  • Compiler validator (src/asahi/compiler/agx_validate_ra.c:216-226):
    • Moves if (!src.has_reg) { all_same = false; first = false; continue; } ahead of assert(ra_class_for_index(src) == cls);.
    • When a non-loop-header PHI is spilled to RA_MEM, an immediate or non-register source (has_reg == false) has no register class, so checking ra_class_for_index(src) == cls first tripped the assert under -Db_ndebug=false even though the very next lines already skipped !src.has_reg sources.
    • Register-backed sources (src.has_reg == true) continue to hit the exact same class assertion and uniformity checks as before.
  • Regression test (src/asahi/compiler/test/test-native-form-regressions.cpp):
    • Adds TEST(NativeForms, RegisterValidationAllowsNonRegSourceInSpilledPhi) constructing a 3-block CFG with a spilled RA_MEM PHI taking one agx_immediate(0) source and one spilled register source, asserting agx_validate_ra(s) succeeds.
  • Verification at 3d89c681: Exact-head J775c (G17C B1, -Db_ndebug=false) ran MALLOC_PERTURB_=42 meson test --suite asahi (348/348 PASS) and live Borealis Vulkan llama-bench (Llama-2-7B Q4_0) cleanly with 0 GPU faults.
  • Non-blocking nit: The PR description refers to the unit test as NativeFormRegressions.ValidateRASpilledPhiImmediateSource, while the diff defines NativeForms.RegisterValidationAllowsNonRegSourceInSpilledPhi.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 3d89c681dd67 from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip d3c21486 + #1317 to #1321) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 3d89c681dd67.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

@RyanTheTide
RyanTheTide merged commit 437b0b5 into aurora-wip Nov 29, 2026
@RyanTheTide
RyanTheTide deleted the satya/fix-validate-ra-spilled-phi branch November 29, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants